package com.xd.common.exception;

import cn.hutool.core.util.StrUtil;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
public class XkdException extends RuntimeException {
    protected int code;

    /**
     * Constructs a new runtime exception with {@code null} as its
     * detail message.  The cause is not initialized, and may subsequently be
     * initialized by a call to {@link #initCause}.
     */
    public XkdException(String tpl, String... param) {
        super(StrUtil.format(tpl, param));
        this.code = EErrorCode.OTHER.getErrorCode();
    }

    public XkdException(EErrorCode errorCode) {
        super(errorCode.getErrorMsg());
        this.code = errorCode.getErrorCode();
    }

    public XkdException(EErrorCode errorCode, String msg) {
        super(msg);
        this.code = errorCode.getErrorCode();
    }

    public XkdException(EErrorCode errorCode, String tpl, String... msg) {
        super(StrUtil.format(tpl, msg));
        this.code = errorCode.getErrorCode();
    }

}
